package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsSightseeingBusPicParam;
import com.macro.mall.dto.BmsSightseeingBusPointParam;
import com.macro.mall.model.BmsSightseeingBusPic;
import com.macro.mall.model.BmsSightseeingBusPoint;
import com.macro.mall.service.BmsSightseeingBusPicService;
import com.macro.mall.service.BmsSightseeingBusPointService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 观光车图片表Controller
 * Created by macro on 2018/4/26.
 */
@Controller
@Api(tags = "BmsSightseeingBusPicController")
@Tag(name = "BmsSightseeingBusPicController", description = "观光车点位管理")
@RequestMapping("/sightseeingBusPic")
public class BmsSightseeingBusPicController {
    @Autowired
    private BmsSightseeingBusPicService bmsSightseeingBusPicService;

    @ApiOperation("添加观光车图片")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsSightseeingBusPicParam bmsSightseeingBusPicParam) {
        int count = bmsSightseeingBusPicService.create(bmsSightseeingBusPicParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }


    @ApiOperation("修改观光车")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsSightseeingBusPicParam bmsSightseeingBusPicParam) {
        int count = bmsSightseeingBusPicService.update(bmsSightseeingBusPicParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
    @ApiOperation("分页查询观光车")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsSightseeingBusPic>> getList(@RequestBody BmsSightseeingBusPicParam bmsSightseeingBusPicParam) {
        List<BmsSightseeingBusPic> bmsSightseeingBusPicList = bmsSightseeingBusPicService.getList(bmsSightseeingBusPicParam);
        return CommonResult.success(CommonPage.restPage(bmsSightseeingBusPicList));
    }

    @ApiOperation("根据id获取观光车信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsSightseeingBusPic> getItem(@PathVariable Long id) {
        BmsSightseeingBusPic bmsSightseeingBusPic = bmsSightseeingBusPicService.getItem(id);
        return CommonResult.success(bmsSightseeingBusPic);
    }

    @ApiOperation("删除观光车")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> delete(@RequestBody List<Long> ids) {
        int count = bmsSightseeingBusPicService.delete(ids);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
}
